package main

import "strings"

func check(m map[byte]int, k int) bool {
	for _, v := range m {
		if v < k {
			return false
		}
	}
	return true
}

func longestSubstring(s string, k int) int {
	m := map[byte]int{}
	for _, c := range s {
		m[byte(c)]++
	}
	for c, v := range m {
		if v < k {
			strs := strings.Split(s, string([]byte{c}))
			max := 0
			for _, s2 := range strs {
				res := longestSubstring(s2, k)
				if res > max {
					max = res
				}
			}
			return max
		}
	}
	return len(s)
}

func main() {
	println(longestSubstring("aaabb", 3))
}